//
// Created by 郝正辉 on 2020/11/21.
//

#ifndef C_TEST_LIST_H
#define C_TEST_LIST_H

#include <stdlib.h>

typedef struct ListElmt_ {
    void *data;
    struct ListElmt_ *next;
} ListElmt;

typedef struct List_ {
    int size;

    /**
     *
     * @param key1
     * @param key2
     * @return
     */
    int (*match)(const void *key1, const void *key2);

    /**
     *
     * @param data
     */
    void (*destroy)(void *data);

    ListElmt *head;
    ListElmt *tail;
} List;

void list_init(List *list, void(*destroy)(void *data));

void list_destroy(List *list);

int list_ins_next(List *list, ListElmt *element, const void *data);

int list_rem_next(List *list, ListElmt *element, void **data);

#define list_size(list) ((list)->size)
#define list_head(list) ((list)->head)
#define list_tail(list) ((list)->tail)

#define list_is_head(list, element) ((element)==(list)->head ?1:0)
#define list_is_tail(element) ((element)->next==NULL ?1:0)
#define list_data(element) ((element)->data)
#define list_next(element) ((element)->next)

#endif //C_TEST_LIST_H
